package cn.itrip.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {

    public static String encode(String oldValue){


        try {
            MessageDigest md5=MessageDigest.getInstance("md5");
            byte[] bs= md5.digest(oldValue.getBytes());

            int c=0;

            StringBuilder stringBuilder=new StringBuilder();
            for (byte b:bs){
                c=b;
                if(c<0){
                    c+=256;
                }
                stringBuilder.append(Integer.toHexString(c));
            }

            return stringBuilder.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }

    }
}
